package com.rk.jvm;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class IteratorCpuMax {

    private static Map<String, Object> dataMap;

    static {
        // read from DB
        dataMap = new HashMap<>();
    }

    public Map<String, Object> deadIterator(Map<String, Object> paramMap) {
        Iterator<String> iterator = paramMap.keySet().iterator();
        while (iterator.hasNext()) {
            for (String keySet : dataMap.keySet()) {
                String key = iterator.next();
                if (key.equals(keySet)) {
                    //System.out.println("same key: " + key);
                }
            }
        }
        return paramMap;
    }

    public static void main(String[] args) throws InterruptedException {
        IteratorCpuMax iteratorCpuMax = new IteratorCpuMax();
        while (true) {
            Map<String, Object> paramMap = new HashMap<>();
            int c = (int) (Math.random() * 5) + 1;
            for (int i = 0; i < c; i++) {
                paramMap.put("key_" + i, "value_" + i);
            }
            iteratorCpuMax.deadIterator(paramMap);
            Thread.sleep(100L);
        }


    }

}
